import os
import logging
from common.time_helpers import current_time

def log_decorator(logger_config):
    def log(cls):
        cls.logger = logging.getLogger(cls.__name__)
        if(logger_config is not None):

            cls.logger.setLevel(level = logger_config["log-level"])
            log_file_path = logger_config["log-file-path"].format(cls.__name__)

            handler = logging.FileHandler(log_file_path)
            handler.setLevel(level = logger_config["log-level"])
            formatter = logging.Formatter(logger_config["log-format"])
            handler.setFormatter(formatter)

            console = logging.StreamHandler()
            console.setLevel(logger_config["log-level"])
            console.setFormatter(logger_config["log-format"])

            cls.logger.addHandler(handler)

        print("*************************************\n" + 
                "logger configuration not specified, using default configs.\n" + 
                "*************************************")
        
        return cls
    return log